import { Component } from '@angular/core';
import { ViewController, NavController } from 'ionic-angular';
import { GLItem } from './GLItem';
import { ListPage } from '../pages/list/list';

@Component({
  templateUrl: '../templates/parentList.html'
})
export class ParentListPage {

  public parents: GLItem[];

  constructor(private viewCtl: ViewController, private navCtrl: NavController) {
    this.parents = [viewCtl.data.item];
    while (true) {
      let currentElem = this.parents[this.parents.length - 1];
      let parent = currentElem.getParentFolder();
      if (parent) {
        this.parents.push(parent);
      }
      else {
        break;
      }
    }
  }

  open(item: GLItem) {
    this.viewCtl.dismiss().then(() => {
      ListPage.open(item, this.navCtrl);
    });
  }
}
